import Taro from "@tarojs/taro";

const navigateTo = (url, events) => {
  Taro.navigateTo({
    url: url,
    events: events || {},
  });
  //跳转
};
//页面跳转
const redirectTo = (url) => {
  Taro.redirectTo({
    url: url,
  });
};
//页面重定向
const switchTab = (url) => {
  Taro.switchTab({
    url: url,
  });
};
//跳转tab页面
const reLaunch = (url) => {
  Taro.reLaunch({
    url: url,
  });
};
//关闭所有页面打开这个页面

export default (routerName, query = {}) => {
  let { args = {}, linkType = "navigateTo" } = query;
  const routerObj = {
    shareCode: "/pages/User/ShareCode/index",
    orderDetails: "/pages/Order/OrderDetails/index",
    orderList: "/pages/Order/OrderList/index",
    login: '/pages/Login/LoginSelect/index',
    loginCode: '/pages/Login/LoginMobile/index',
    home: '/pages/Home/ExamPage/index',
    information: '/pages/Home/Information/index',
    shareCode: '/pages/User/ShareCode/index',
    myMutuaList: '/pages/User/MyMutuaList/index',
    myCollect: '/pages/User/MyCollect/index',
    qaRecord: '/pages/User/QaRecord/index',
    addressBookList: '/pages/User/AddressBookList/index',
    collectWps: '/pages/Shop/CollectWps/index',
    SetAddressBook: '/pages/Shop/SetAddressBook/index',
    wxPageInfo: '/pages/Shop/WxPageInfo/index',
    selectedCourses: "/pages/User/SelectedCourses/index",
    course: "/pages/User/Course/index",
    payShopDetail: "/pages/Shop/PayShopDetail/index",
    formList: "/pages/Shop/FormList/index",
    shopList: "/pages/Shop/ShopList/index",
    shopDetail: "/pages/Shop/ShopDetail/index",
    liveInteraction: "/pages/Shop/SetEmpty/index",
    payLiveInteraction: "/pages/Shop/Empty/index",
    renderLink: "/pages/Shop/RenderLink/index",
    videoDetails: "/pages/Shop/VideoDetails/index",
    webView: "/pages/Shop/WebView/index",
    prizeList: '/pages/Shop/PrizeList/index',
    payOrder: "/pages/Order/PayOrder/index",
    orderWeex: "/pages/Order/OrderWeex/index",
    MutualList: '/pages/Shop/MutualList/index',
    MutualQuestion: '/pages/Shop/MutualQuestion/index',
    MutualAll: '/pages/Shop/MutualAll/index',
    MutualAsk: '/pages/Shop/MutualAsk/index',
    MutualDetail: '/pages/Shop/MutualDetail/index',
    MyMutuaList: '/pages/Shop/MyMutuaList/index',
    FormDemo: '/pages/Shop/FormDemo/index',
  }[routerName];
  if (typeof args === "object") {
    args = Object.keys(args)
      .map((item) => {
        return `${item}=${args[item]}`;
      })
      .join("&");
  }
  switch (linkType) {
    case "navigateTo":
      return navigateTo(routerObj + (args ? `?${args}` : ""));
    case "redirectTo":
      return redirectTo(routerObj + (args ? `?${args}` : ""));
    case "switchTab":
      return switchTab(routerObj + (args ? `?${args}` : ""));
    case "reLaunch":
      return reLaunch(routerObj + (args ? `?${args}` : ""));
  }
};
